<template>
  <el-dialog title="经济能力" :visible.sync="dialogVisible" width="1100px">
    <div v-loading="dialoading">
      <h2>{{ cert_name }}经济能力详情</h2>
      <br>
      <el-row>
        <el-col :span="8">报告生成时间：{{ start_at }}</el-col>
        <el-col :span="8">订单ID：{{ editItem.id || editItem.order_id }}</el-col>
      </el-row>
      <br>
      <el-row>
        <el-col>
          <el-descriptions title="" direction="vertical" :column="3" border>
            <el-descriptions-item label="用户经济收入">{{ allData1?.score?.money ? '0' : econList[allData1.score - 1].money
              }}</el-descriptions-item>
            <el-descriptions-item label="建议授信额度(最低)">{{ lower == {} ? '0' : tableData[lower].interval
              }}</el-descriptions-item>
            <el-descriptions-item label="建议授信额度(最高)">{{ height == {} ? '0' : tableData[height].interval
              }}</el-descriptions-item>
          </el-descriptions>
        </el-col>
      </el-row>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="dialogVisible = false">关闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { getAntRiskData } from '@/api/order'
export default {
  props: {
    editItem: {
      type: Object,
      default: () => ({})
    },
  },
  data() {
    return {
      dialoading: false,
      dialogVisible: false,
      cert_name: '',
      start_at: '',
      level: '',
      allData1: {},
      allData2: [],
      height: '',
      lower: '',
      tableData: [{ interval: '[1000,2000]', number: 0 },
      { interval: '[2001,4000]', number: 1 },
      { interval: '[4001,6000]', number: 2 },
      { interval: '[6001,8000]', number: 3 },
      { interval: '[8001,10000]', number: 4 },
      { interval: '[10001,15000]', number: 5 },
      { interval: '[15001,20000]', number: 6 },
      { interval: '[20001,30000]', number: 7 },
      { interval: '[30001,50000]', number: 8 },
      { interval: '[50001,100000]', number: 9 }],
      econList: [{ money: '<=2000', id: 1 },
      { money: '2000~4000', id: 2 },
      { money: '4000~6000', id: 3 },
      { money: '6000~8000', id: 4 },
      { money: '8000~10000', id: 5 },
      { money: '10000~12000', id: 6 },
      { money: '12000~15000', id: 7 },
      { money: '15000~20000', id: 8 },
      { money: '20000~25000', id: 9 },
      { money: '>25000', id: 10 }]
    }
  },
  watch: {
    dialogVisible(val) {
      if (val) {
        this.$nextTick(() => {
          this.getList()
        })
      }
    }
  },
  methods: {
    format(percentage) {
      return percentage == percentage ? percentage.toFixed(2) : '0'
    },
    getList() {
      // 1 额度评级分V2
      // 2 反欺诈价值分V4
      // 3 风险前筛V1
      // 4 经济能力评级分
      // 5 信贷洞察分V3
      let params = {
        num: '1',
        orderId: this.editItem?.id || this.editItem?.order_id,
        cert_name: this.editItem?.authentic?.cert_name || this?.editItem?.cert_name,
        cert_no: this.editItem?.authentic?.cert_no || this.editItem?.cert_no,
        mobile: this.editItem.mobile
      }
      let params1 = {
        num: '4',
        orderId: this.editItem?.id || this.editItem?.order_id,
        cert_name: this.editItem?.authentic?.cert_name || this?.editItem?.cert_name,
        cert_no: this.editItem?.authentic?.cert_no || this.editItem?.cert_no,
        mobile: this.editItem.mobile
      }
      this.dialoading = true
      Promise.allSettled([getAntRiskData(params), getAntRiskData(params1)]).then(values => {
        let res1 = values[0].status == 'fulfilled' ? values[0].value : ""
        let res2 = values[1].status == 'fulfilled' ? values[1].value : ""
        if (res1) {
          res1.variable_details.forEach(item => {
            if (item.variableName == 'creditlimit_V2_lower') {
              this.lower = item.variableValue
            } else {
              this.height = item.variableValue
            }
          });
        }
        if (res2) {
          this.allData1 = res2.model_details[0]
          this.start_at = res2.start_at
          this.cert_name = res2.cert_name
          if (this.allData1.score == -1) {
            this.$message({
              message: '用户未查得',
              type: 'error'
            })
          } else if (this.allData1.score == -99) {
            this.$message({
              message: '查询异常',
              type: 'error'
            })
          }
        }
        this.dialoading = false
      }).catch(()=>{
        this.dialoading = false
      })
    }
  }
}
</script>

<style lang="scss" scoped></style>
